package org.wlgzs.office_exam_student.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *
 * @author  孤城落寞博客
 *   注销界面  防倒退
 */

@WebServlet("/logout")
public class LogoutServlet extends BaseServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //清空session信息
        request.getSession().removeAttribute("user");

        //  也可以一起使用
        // 退出登录的时候清空cookie信息,cookie需要通过HttpServletRequest，HttpServletResponse获取
//        Cookie[] cookie=request.getCookies();
//        for(Cookie c:cookie){
//            if("autoLogin".equals(c.getName())){
//                c.setMaxAge(0);
//                response.addCookie(c);
//            }
//        }
//        Object user = request.getSession().getAttribute("user");
//        System.out.println("user"+user);
        render("/logout");
    }
}
